// 导入api接口
import { empWarnConfigadd, empWarnConfigdelete, empWarnConfigList, empWarnConfigupdate } from "@/api/api";
import { mapState, mapGetters } from 'vuex'
import configJs from '@/utils/configJs';
import defaultData from './data';
var data = JSON.parse(JSON.stringify(defaultData))
var adapter = {
	data,
	methods: {
		// ...mapActions(['logOut']),
		/**
		 * 初始化
		 */
		initPage(){
			//还原页面对象
			configJs.revert(data, defaultData);
		},
		initempWarnConfigList(){
			//获取数据
			empWarnConfigList().then((res)=>{
				console.log(res.data)
				this.page = res.data
			})
		},
		save(){
			// console.log(this.editdata)
			if(this.editdata.id == ""){
				this.$message({
					type: 'info',
					message: `请进行修改之后在保存`
				});
			}else{
				empWarnConfigupdate(this.editdata).then((res)=>{
					console.log(res)
					if (res.code === 0) {
						this.$message({
							type: 'success',
							message: `修改成功`
						});
						this.editVisi = false
						this.initempWarnConfigList()
					} else {
						this.$message({
							type: 'info',
							message: `修改失败`
						});
					}
				})
			}
		},
		add(){
			this.addVisi = true
			this.addStaff ={
				yryjlx: '',
				tqxtyj: '',
				bz: ''
			}
		},
		addClick(){
			console.log(this.adddata[0])
			empWarnConfigadd(this.adddata[0]).then((res)=>{
				console.log(res)
				if (res.code === 0) {
					this.$message({
						type: 'success',
						message: `修改成功`
					});
					this.addVisi = false
					this.initempWarnConfigList()
				} else {
					this.$message({
						type: 'info',
						message: `修改失败`
					});
				}
			})
		},
		edit(item){
			// console.log(item)
			this.editdata = {...item}
			this.editVisi = true;	
		},

		rowClick(){
			
		},
		deleteClick(id){
			console.log(id)
			let that = this;
			this.$confirm('是否删除该条消息', '删除', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				empWarnConfigdelete(id).then((res)=>{
					// console.log(res)
					that.$message({
						type: 'success',
						message: '删除成功!'
					});
					that.initempWarnConfigList()
				}) 
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});          
			});
		}
			
	},
	computed: {
		...mapState({
			supperAdmin: state => state.user.supperAdmin,
		}),
		...mapGetters(['userPageAuth']),
	}
}
export default adapter
